package com.ssmdemo.service.imp.empimpl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.ssmdemo.dao.DeptMapper;
import com.ssmdemo.pojo.Dept;
import com.ssmdemo.service.DeptService;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class DeptServiceImp extends ServiceImpl<DeptMapper,Dept> implements DeptService{

    public Page selectDeptPage(Page page) {

        int current=page.getCurrent();
        int size=page.getSize();

        Integer total=super.baseMapper.selectCount(null);

        List<Dept> list=baseMapper.selectDeptPage((current-1)*size,size);


        page.setTotal(total);
        page.setRecords(list);
        return page;
    }

    public List<Dept> getDeptListByPerentId(Integer id) {
//        EntityWrapper entityWrapper=new EntityWrapper();
//        entityWrapper.eq("parent_id",id);
//        List<Dept> list=baseMapper.selectList(entityWrapper);

        List<Dept> list=baseMapper.selectDeptListByParentId(id);

        return list;

    }

    public int insertDept(Dept dept) {
        baseMapper.insertDept(dept);
        return 1;
    }

    public int updateDept(Dept dept) {
        baseMapper.updateDept(dept);
        return 1;
    }


}